<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <link href="__STATIC__/Admin/css/base.css" rel="stylesheet" type="text/css" />
    <link href="__STATIC__/Admin/css/right.css" rel="stylesheet" type="text/css">
    <link href="__STATIC__/css/page.css" rel="stylesheet" type="text/css">
    <script language="JavaScript" src="__STATIC__/js/jquery-2.1.1.min.js"></script>
    <script src="__STATIC__/js/datejs/laydate.js"></script>

    <script>
        $(document).ready(function(){
            $(function(){
                $('.rightinfo tbody tr:odd').addClass('odd')
            });
        });
    </script>
</head>

<body>
<div class="place"> <span>位置：</span>
    <ul class="placeul">
        <li><a href="{:url('Index/center')}">首页</a></li>
        <li>正在进行</li>
    </ul>
</div>
<div class="rightinfo">
    <h1 style="font-size:18px;text-align:center;"><span class="qi_name" style="font-size:24px;color:red;"></span>期，距开奖还有
    <span id="seconds" style="font-size:24px;color:red;">0</span>s
    </h1>
     <h1 style="font-size:14px;text-align:center;">在线人数
    <span id="onlinecount" style="font-size:20px;color:red;">0</span>
    </h1>
    <table class="tablelist">
        <thead>
        <tr>
            <th>期数</th>
            <th>总金额</th>
            <th>小</th>
            <th>大</th>
            <th>小双</th>
            <th>小单</th>
            <th>大单</th>
            <th>大双</th>
            <th>合</th>
            <th>结果</th>
            <th>盈利</th>
        </tr>
        </thead>
        <tbody>
        <tr height="40" align="center">
            <td class="qi_name"></td>
            <td id="total"></td>
            <td id="small"></td>
            <td id="big"></td>
            <td id="smallDouble"></td>
            <td id="smallSingle"></td>
            <td id="bigSingle"></td>
            <td id="bigDouble"></td>
            <td id="he"></td>
            <td id="t_res">暂无</td>
            <td id="t_yingli">暂无</td>
        </tr>
        </tbody>
    </table>
    
    <div class="flex">
   	<div>
   	<table class="tablelist" style="width:250px;">
        <thead>
        <tr>
            
            <th>精准</th>
            <th>数字</th>
            <th>金额</th>
        </tr>
        </thead>
        <tbody id="tr_jz">
        
        </tbody>
    </table>
    </div>
    <style>
    .aaaaa *{
	font-size:20px;
    }
    
    </style>
    <div class="aaaaa flex-1" style="font-size:20px;">
    <div>最终开奖结果：<span id="last_res"></span>，总金额：<span id="last_money"></span>，盈利：<span id="last_yingli"></span></div>
    <div>
    <h2>修改开奖结果
    {if($qiinfo['is_hand']==1)}
    <span style="color:red;">
    （已修改结果：结果为{$qiinfo['result']}，盈利：{$qiinfo['yingli_money']/100}）
    </span>
    {/if}
    </h2>
    <input id="number" name="number" type="number" oninput="if(value.length>3)value=value.slice(0,3)" value="" class="dfinput" style="width:100px;text-align:center;">
    盈利：<span id="counts_yingli">0</span>
    <input id="counts" type="submit" name="button" class="btn" value="计算" />
    <input id="edits" type="submit" name="button" class="btn" value="确认修改" />
    </div>
    </div>
    </div>
</div>

<script>
var apihost = "{$apihost}";

    $(function () {
    	connect();
        $("#mod").click(function () {
            var tmp = prompt('设置开奖结果为');
            if(tmp) {
                alert(tmp);
            }
        });
        
        $("#edits").click(function () {
            var value = $("#number").val();
            if(!isEmpty(value)&&value.length==3){
            	gres(value);
            }else{
			alert("请输入三位的数字");
			}
        });
        $("#counts").click(function () {
            var value = $("#number").val();
            if(!isEmpty(value)&&value.length==3){
            	$.post(apihost + "getyingli",{num:value},function(jsondata){
            		if(jsondata.flag!=0){
            			alert(jsondata.msg);
            		}else{
            			$("#counts_yingli").text(jsondata.data);
            		}
            	});
            }else{
			alert("请输入三位的数字");
			}
        });
    });
    function openStart(){
    	$.get(apihost + "openGame");
    }
    function kjl(){
    	$.get(apihost + "kaijaing");
    }
    function gres(r){
    	$.post(apihost + "gres",{num:r},function(jsondata){
    		if(jsondata.flag!=0){
    			alert(jsondata.msg);
    		}else{
    			alert("修改成功");
    			location.reload();
    		}
    	});
    }
    var curr_time_count; 
    function getNowInfo() {
    	
    	$.get(apihost + "getResult",
    					function(data) {
    		
    						if (isEmpty(data)) {
    							
    						} else {
    							$("#last_res").text("待开奖");
    			    			$("#last_money").text("待开奖");
    			    			$("#last_yingli").text("待开奖");
    			    			$("#t_res").text("暂无");
    			    			$("#t_yingli").text("暂无");
    							var curr = data.curr;
    							var allmoney = data.allmoney;
    							$("#small").html(allmoney.small);
    							$("#big").html(allmoney.big);
    							$("#smallDouble").html(allmoney.smallDouble);
    							$("#smallSingle").html(allmoney.smallSingle);
    							$("#bigSingle").html(allmoney.bigSingle);
    							$("#bigDouble").html(allmoney.bigDouble);
    							$("#he").html(allmoney.he);
    							$("#total").html(allmoney.total);
    							$("#tr_jz").empty();
    							var jz = allmoney.jz;
    							for(var i=0;i<jz.length;i++){
    								var html='<tr height="40" align="center" style="border:1px dashed #ccc;"><td>精准</td>'+
    						            
    						            '<td>'+jz[i].num+'</td><td>'+jz[i].money+'</td></tr>';
    						            $("#tr_jz").append(html);
    							}
    							
    							$(".qi_name").html(curr.name);
    							var time = curr.times;
								if(curr_time_count){
								clearInterval(curr_time_count);
    							}
								curr_time_count = setInterval(function(){
								if(time<=0){
									time=0;
									clearInterval(curr_time_count);
									kjl();
								}
								$("#seconds").html(time);
    								time--;    								
    							},1000);
    							
    							
    							
    							
    							
    							
    						}
    					});
    }
    function connect() {
    	//ws = new WebSocket("ws://222.189.228.172:8282");
    	ws = new WebSocket("ws://{$pushhost}");
    	ws.onerror = function() {
    		connect();
    	};
    	ws.onclose = function() {
    		connect();
    	};
    	ws.onmessage = function(e) {
    		// json数据转换成js对象
    		var data = eval("(" + e.data + ")");
    		var type = data.type || '';
    		switch (type) {
    		case "ping":
    			ws.send('{"type":"pong"}');
    			break;
    		case "refresh":
    			getNowInfo();

    			break;
    		case "moneychange":
    			getNowInfo();
    			break;
    		case "result":
    			setTimeout(function(){
    				openStart();
    			},4000);
    			break;
    		case "kjinfo":
    			var kajinginfo = data.data;
    			$("#last_res").text(kajinginfo.result);
    			$("#last_money").text(parseFloats(kajinginfo.total_money/100));
    			$("#last_yingli").text(parseFloats(kajinginfo.yingli_money/100));
    			$("#t_res").text(kajinginfo.result);
    			$("#t_yingli").text(parseFloats(kajinginfo.yingli_money/100));
    			break;
    		case "countChange":
    			
    			$("#onlinecount").html(data.data);
    			break;
    		// Events.php中返回的init类型的消息，将client_id发给后台进行uid绑定
    		case 'init':
    			// 利用jquery发起ajax请求，将client_id发给后端进行uid绑定
    			$.post(apihost+'bind', {
    				client_id : data.client_id
    			}, function(res) {
    				openStart();
    				getNowInfo();
    			}, 'json');
    			break;
    		}
    	};
    }    
  //是否为空
    function isEmpty(str) {

    	if(str == undefined || str == null || str == "" || str == 'null' || str.length == 0) {
    		return true;
    	} else {
    		return false;
    	}
    }

    function parseFloats(a) {
    	return parseFloat(a).toFixed(2);
    }
</script>

</body>
</html>